package logic

import (
	"context"
	"hui-hui/hui_hui_rpc/huihuirpcclient"

	"hui-hui/api/internal/svc"
	"hui-hui/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RestLogic {
	return &RestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RestLogic) Rest(req *types.RestRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	rest, err := l.svcCtx.HuiHuiRoc.Rest(l.ctx, &huihuirpcclient.RestRequest{
		Phone:    req.Phone,
		Code:     req.Code,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "账号注册成功",
		Data:    rest,
	}, nil
}
